package com.jack.leetcode.string;

/**
 * Created by zhang_j on 2020/7/8
 */
public class 实现strstr {

    public static void main(String[] args) {
        System.out.println(strStr("aaaaa","bc"));
        System.out.println(strStr("hello","ll"));
        System.out.println("hello".indexOf("ll"));
    }

    public static int strStr(String haystack, String needle) {
        if(needle == null || needle.isEmpty()){
            return 0;
        }
        int n = haystack.length();
        int m = needle.length();
        StringBuilder stringBuilder = new StringBuilder(haystack);
        int result = -1;
        for(int i = 0;i < n-m+1;i++){
            if(stringBuilder.substring(i,i+m).equalsIgnoreCase(needle)){
                return i;
            }
        }
        return result;
    }
}
